package com.lyf.scm.admin.domain.service.impl;

import com.github.pagehelper.PageInfo;
import com.lyf.scm.admin.api.dto.OperationLogRecordDTO;
import com.lyf.scm.admin.domain.remote.allocationservice.facade.*;
import com.lyf.scm.admin.domain.service.OperationLogRecordService;
import com.lyf.scm.common.enums.OperationDataEnum;
import com.rome.user.common.utils.UserContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author: huangtao
 * @Description: 操作日志
 * @Date: create in 2020/10/5
 */
@Slf4j
@Service
public class OperationLogRecordServiceImpl implements OperationLogRecordService {

    @Resource
    private OperationLogRecordFacade operationLogRecordFacade;

    @Resource
    private SalesPlanFacade salesPlanFacade;

    @Resource
    private DirectlyExecuteFacade directlyExecuteFacade;

    @Resource
    private DirectlyStoreFacade directlyStoreFacade;

    @Resource
    private GmvTargetFacade gmvTargetFacade;

    @Resource
    private SalePlanDirectlyDifferinFacade salePlanDirectlyDifferinFacade;

    @Resource
    private SalesPlanDirectlyAccuracyFacade salesPlanDirectlyAccuracyFacade;

    @Resource
    private SalesPlanDirectlyFacade salesPlanDirectlyFacade;

    @Resource
    private SalesPlanOtherAccuracyFacade salesPlanOtherAccuracyFacade;

    @Resource
    private SalesPlanOtherDifferinFacade salesPlanOtherDifferinFacade;

    @Resource
    private SalesPlanOtherFacade salesPlanOtherFacade;

    /**
     * 获取操作日志
     *
     * @param OperationLogRecord
     * @return
     */
    @Override
    public PageInfo<OperationLogRecordDTO> getOperationLogs(OperationLogRecordDTO OperationLogRecord) {
        Long userId = UserContext.getUserId();
        OperationLogRecord.setCreator(userId);
        return operationLogRecordFacade.getOperationLogs(OperationLogRecord);
    }

    @Override
    public void delete(String opSign, Integer type) {
        if (OperationDataEnum.DIRECTLY_EXECUTE.getTableType().equals(type)) {
            directlyExecuteFacade.delete(opSign);
        } else if (OperationDataEnum.DIRECTLY_SHOP.getTableType().equals(type)) {
            directlyStoreFacade.delete(opSign);
        } else if (OperationDataEnum.DIRECTLY_ACCURACY.getTableType().equals(type)) {
            salesPlanDirectlyAccuracyFacade.delete(opSign);
        } else if (OperationDataEnum.DIRECTLY_DIFFERIN.getTableType().equals(type)) {
            salePlanDirectlyDifferinFacade.delete(opSign);
        } else if (OperationDataEnum.PLAN_DIRECTLY.getTableType().equals(type)) {
            salesPlanDirectlyFacade.delete(opSign);
        } else if (OperationDataEnum.PLAN_DEMAND.getTableType().equals(type)) {
            salesPlanFacade.delete(opSign);
        } else if (OperationDataEnum.SALES_TARGET.getTableType().equals(type)) {
            gmvTargetFacade.delete(opSign);
        } else if (OperationDataEnum.OTHER_PLAN.getTableType().equals(type)) {
            salesPlanOtherFacade.delete(opSign);
        } else if (OperationDataEnum.OTHER_PLAN_DIFFERENCE.getTableType().equals(type)) {
            salesPlanOtherDifferinFacade.delete(opSign);
        } else if (OperationDataEnum.OTHER_PLAN_ACCURACY.getTableType().equals(type)) {
            salesPlanOtherAccuracyFacade.delete(opSign);
        }
        //修改删除状态
        operationLogRecordFacade.updateToDel(opSign);
    }

    @Override
    public void bigDataInitiating() {
        operationLogRecordFacade.bigDataInitiating();
    }

    @Override
    public void rmByOpSign(List<OperationLogRecordDTO> operationLogRecordDTOs) {
        operationLogRecordFacade.rmByOpSign(operationLogRecordDTOs);

    }

    @Override
    public void opLogInitiating(List<Long> ids) {
        operationLogRecordFacade.opLogInitiating(ids);
    }
}
